var utils = require('/utils/index.js');
var base = require('/base_info.js');
Page({
  data: {
    hotel_img: [],
    imgUrl: base.imgUrl,
    room_img: [],
    showImg: '',
    modelSign: false
  },
  // 点击图片预览
  imgClick (e) {
    let that = this;
    var imgList = [];
    var index = e.currentTarget.dataset.index;
    var sign = e.currentTarget.dataset.sign;
    var room_img = that.data.room_img;
    var hotel_img = that.data.hotel_img;
    console.log(index);
    if (sign == 'hotel') {
      imgList = [...hotel_img.slice(index), ...room_img, ...hotel_img.slice(0, index)];
    } else {
      imgList = [...room_img.slice(index), ...hotel_img, ...room_img.slice(0, index)];
    }
    Array.from(imgList, (item, index) => imgList[index] = that.data.imgUrl + item);
    my.previewImage({
      current: 20,
      urls: imgList
    });
  },
  // 请求数据
  getData (room_id) {
    let that = this;
    that.setData({
      hotel_img: JSON.parse(my.getStorageSync({
        key: 'hotel_info', // 缓存数据的key
      }).data).img.split(",")
    })
    my.showLoading({});
    // 获取房间详情数据
    utils.getData('SingleRoomDetails', {
      room_id: room_id,
      start: my.getStorageSync({
        key: 'inTime',
      }).data,
      end: my.getStorageSync({
        key: 'outTime',
      }).data
    }, (res) => {
      my.hideLoading();
      that.setData({
        room_img: res.data.data.img.split(","),
        room_info: res.data.data
      })
    }, (err) => {
      my.hideLoading();
    })
  },
  onLoad(query) {
    // 页面加载
    this.getData(query.id);
  }
})